<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1400px">
            <div class="card card-search">
                <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="120px">
                    <el-form-item label="商品SPU" prop="spu">
                        <el-input v-model.trim="queryParams.spu" placeholder="请输入SPU" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <!-- <el-form-item label="供应商" prop="supply_id">
                        <SelectPage
                            v-model="queryParams.supply_id"
                            placeholder="请选择供应商"
                            :url="$api.supply.getSupplyList"
                            show_field="supply_name"
                            query_field="supply_name"
                            query_field2="spu"
                            filterable
                            clearable
                            popper-class="custom-select"
                            style="width: 240px"
                        ></SelectPage>
                    </el-form-item> -->
                    <el-form-item label="创建时间" prop="create_time">
                        <el-date-picker v-model="queryParams.create_time" format="yyyy-MM-dd" type="daterange" start-placeholder="开始时间" end-placeholder="结束时间" style="width: 240px"></el-date-picker>
                    </el-form-item>
                    <el-form-item label=" ">
                        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table v-loading="loading" :data="tableData" border script>
                <el-table-column label="ID" prop="id" min-width="80"></el-table-column>
                <el-table-column label="商品SPU" prop="spu" min-width="">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="showSkuListDialog(scope.row)">{{ scope.row.spu }}</el-link>
                    </template>
                </el-table-column>
                <el-table-column label="图片" min-width="100">
                    <template slot-scope="scope">
                        <ImageUploadImg v-model="scope.row.product_images" :readOnly="true"></ImageUploadImg>
                    </template>
                </el-table-column>
                <el-table-column label="当日销量" prop="material" min-width=""></el-table-column>
                <el-table-column label="当日缺货数量" prop="material" min-width=""></el-table-column>
                <el-table-column label="供应商" prop="material" min-width=""></el-table-column>
                <el-table-column label="创建日期" prop="material" min-width=""></el-table-column>
                <!-- <el-table-column label="操作" min-width="100"  fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-edit" @click="showDetailDialog(scope.row)">编辑</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
    </el-dialog>
</template>

<script>
import { queryOrderCheckSpuList,exportOrderCheckSpuList } from '@/api/order'
export default {
    name: 'SkuListDialog',
    components: { },
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            tableData: [],
            // 查询参数
            queryParams: {
                ordercheck_id: undefined,
                spu: undefined,
                date: []
            },
            showSearch: true,
        }
    },
    computed: {
        title() {
            return `SKU列表`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    
    created() {
        this.getList()
    },
    
    methods: {
        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.date?.length == 2) {
                qyparams.date = [parseTime(qyparams.date[0], 'y-m'), parseTime(qyparams.date[1], 'y-m')]
            }
            queryOrderCheckSpuList(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    this.total = response.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },
        handleExport() {
            this.download = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.date?.length == 2) {
                qyparams.date = [parseTime(qyparams.date[0], 'y-m'), parseTime(qyparams.date[1], 'y-m')]
            }
            exportOrderCheckSpuList(qyparams)
                .then(res => {
                    exportFile(res, () => {
                        this.download = false
                    })
                })
                .catch(err => {
                    this.download = false
                })
        },

        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },


    },
}
</script>

<style></style>
